<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>角色管理</title>
    <#include "../common/link.ftl">
    <script>
        $(function () {
            //新增/编辑按钮点击事件
            $(".btn_redirect").click(function () {
                //清除模态框的数据
                //数据复原
                $("#editForm input").val('');
                $("#editForm textarea").val('');
                //$("#editForm")[0].reset(); //不能清除隐藏域
                //获取事件源绑定的数据 使用data方法可以很方便获取data-*开头的属性的数据
                var json = $(this).data("json");
                console.log(json)
                if(json){ //json有数据代表是编辑
                    $(".modal-title").html("角色编辑");
                    $("#editForm input[name='id']").val(json.id);
                    $("#editForm input[name='name']").val(json.name);
                    $("#editForm textarea[name='sn']").val(json.sn);
                }

                //打开模态框
                $("#myModal").modal('show');
            })

            //保存
            $(".btn-submit").click(function () {
                //使用jquery-form插件来提交异步表单(有表单时会使用该插件,写的代码比较少)
                $("#editForm").ajaxSubmit(handlerMessage)
            })

            //删除按钮
            $(".btn-delete").click(function () {
                //获取当前点击的部门id
                var id = $(this).data('id');
                //提示确认框
                $.messager.confirm("警告","是否确认删除?",function () {
                    //发送ajax请求
                    $.get('/role/delete.do',{id:id},handlerMessage)
                })
            })
        })
    </script>
</head>
<body class="hold-transition skin-blue sidebar-mini">
<div class="wrapper">
    <#include "../common/navbar.ftl">
    <!--菜单回显-->
    <#assign currentMenu="role"/>
    <#include "../common/menu.ftl">
    <div class="content-wrapper">
        <section class="content-header">
            <h1>角色管理</h1>
        </section>
        <section class="content">
            <div class="box">
                <!--高级查询--->
                <div style="margin: 10px;">
                    <!--高级查询--->
                    <form class="form-inline" id="searchForm" action="/role/list.do" method="post">
                        <input type="hidden" name="currentPage" id="currentPage" value="1">
                        <#--<a href="#" class="btn btn-success btn_redirect"><span class="glyphicon glyphicon-plus"></span> 添加</a>-->
                    </form>

                    <table class="table table-striped table-hover" >
                        <thead>
                        <tr>
                            <th>编号</th>
                            <th>角色名称</th>
                            <th>备注</th>
                            <th>操作</th>
                        </tr>
                        </thead>
                        <#list page.list as role>
                           <tr>
                               <td>${role_index+1}</td>
                               <td>${role.name!}</td>
                               <td>${role.sn!}</td>
                               <td>
                                   <a href="/role/input.do?id=${role.id}" class="btn btn-success btn-xs btn_delete" >
                                       <span class="glyphicon glyphicon-tag"></span> 权限分配
                                   </a>
                                   <a href="javascript:;" class="btn btn-info btn-xs btn_redirect"  data-json='${role.jsonString}'>
                                       <span class="glyphicon glyphicon-pencil"></span> 编辑
                                   </a>
                                   <#--<a href="javascript:;" class="btn btn-danger btn-xs btn-delete"  data-id='${role.id}'>-->
                                       <#--<span class="glyphicon glyphicon-trash"></span> 删除-->
                                   <#--</a>-->
                               </td>
                           </tr>
                      </#list>
                    </table>
                    <!--分页-->
                    <#include "../common/page.ftl">
                </div>
            </div>
        </section>
    </div>
    <#include "../common/footer.ftl">
</div>

<!-- Modal模态框 -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="myModalLabel">角色新增/编辑</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" action="/role/saveOrUpdate.do" method="post" id="editForm">
                    <input type="hidden" name="id" id="modelId">
                    <div class="form-group" style="margin-top: 10px;">
                        <label for="name" class="col-sm-3 control-label">角色名称：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" name="name"
                                   placeholder="请输入角色名称" readonly>
                        </div>
                    </div>

                    <div class="form-group" style="margin-top: 10px;">
                        <label for="sn" class="col-sm-3 control-label">备注：</label>
                        <div class="col-sm-6">
                            <textarea class="form-control" name="sn" id="sn"></textarea>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                <button type="button" class="btn btn-primary btn-submit">保存</button>
            </div>
        </div>
    </div>
</div>
</body>
</html>
